package day06;

import java.util.Scanner;

public class CalTotaAvg {
    public static void main(String[] args) {
        double[] scores = inputData(6);
        double avg = calAvg(scores);
        System.out.println("平均分为：" + avg);

    }

    public static double[] inputData(int n) {
        double[] scores = new double[n];
        Scanner scan = new Scanner(System.in);
        for (int i = 0; i < n; i++) {
            System.out.print("请输入第" + (i + 1) + "位评委分数:");
            scores[i] = scan.nextDouble();
        }
        return scores;
    }

    public static double calAvg(double[] scores){
        double total = 0.0; //总分
        double max = scores[0]; //假设第1个元素为最高分
        double min = scores[0]; //假设第1个元素为最低分
        for(int i=0;i<scores.length;i++){
            total += scores[i]; //累加所有评分
            if(scores[i]>max){ //找最高分
                max = scores[i];
            }
            if(scores[i]<min){ //找最低分
                min = scores[i];
            }
        }
        //计算平均分---总分减掉最高分和最低分之后，再除以(评委数-2)
        double avg = (total-max-min)/(scores.length-2);
        return avg;
    }

/*
    public static double claAvg(double[] scores) {
        double avg;
        double sum = 0.0;
        Arrays.sort(scores);
        for (int i = 1; i < scores.length - 1; i++) {
            sum += scores[i];
        }
        avg = sum / (scores.length - 2);
        return avg;
    }

 */
}
